<extend name="./public/frame.html"/>
<block name="content">
    <form class="layui-form" action="" enctype="multipart/form-data" id="formId" autocomplete="off">
        <input type="hidden" name="car_id" value="{$info.car_id}"/>
        <!--<input type="hidden" name="driver_id" value="{$info.driver_id}"/>-->
        <table class="layui-table">
            <tr>
                <td style="width: 118px;text-align: center;">*车辆所属公司</td>
                <td><input type="text" name="belong_company" id="belong_company" class="layui-input" lay-verify="required" value="{$info['belong_company']}" title=""></td>
            </tr>
            <tr>
                <td style="text-align: center;">*车辆所在城市</td>
                <td>
                    <div class="layui-inline">
                        <select name="province_id" id="province_id" lay-verify="required" lay-filter="province">
                            <if condition="$region_data['province_id']">
                                <option value="{$region_data['province_id']}">{$region_data['province_name']}</option>
                            <else />
                                <option value="">请选择省份</option>
                            </if>
                            <volist name="province" id="vo">
                            <option value="{$vo['region_id']}">{$vo['region_name']}</option>
                            </volist>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <select name="city_id" id="city_id" lay-filter="city">
                            <if condition="$region_data['city_id']">
                                <option value="{$region_data['city_id']}">{$region_data['city_name']}</option>
                            <else />
                                <option value="">请选择城市</option>
                            </if>
                        </select>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="text-align: center;">*车牌颜色</td>
                <td>
                    <select name="plate_color" id="plate_color" lay-filter="plate_color" lay-verify="required">
                        <if condition="$plate_color_select">
                            <volist name="plate_color_select" id="vo">
                                <option value="{$key}">{$vo}</option>
                            </volist>
                            <else />
                            <option value="">请选择颜色</option>
                        </if>
                        <volist name="plate_color" id="vo">
                            <option value="{$key}">{$vo}</option>
                        </volist>
                    </select>
                </td>
            </tr>
            <tr>
                <td style="text-align: center;">*核定载客位</td>
                <td><input type="text" name="approve_passenger" id="approve_passenger" class="layui-input" lay-verify="required" value="{$info['approve_passenger']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*车辆厂牌</td>
                <td><input type="text" name="car_label" id="car_label" class="layui-input" lay-verify="required" value="{$info['car_label']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*车辆类型</td>
                <td><input type="text" name="car_type" id="car_type" class="layui-input" lay-verify="required" value="{$info['car_type']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*发动机号</td>
                <td><input type="text" name="engine_id" id="engine_id" class="layui-input" lay-verify="required" value="{$info['engine_id']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*车辆VIN码</td>
                <td><input type="text" name="vin" id="vin" class="layui-input" lay-verify="required" value="{$info['vin']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*发动机型号</td>
                <td><input type="text" name="engine_type" id="engine_type" class="layui-input" lay-verify="" value="{$info['engine_type']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*燃料类型</td>
                <td>
                    <select name="energy_type" id="energy_type" lay-filter="energy_type" lay-verify="required">
                        <if condition="$energy_type_select">
                            <volist name="energy_type_select" id="vo">
                                <option value="{$key}">{$vo}</option>
                            </volist>
                            <else />
                            <option value="">请选择燃料类型</option>
                        </if>
                        <volist name="energy_type" id="vo">
                            <option value="{$key}">{$vo}</option>
                        </volist>
                    </select>
                </td>
            </tr>
            <tr>
                <td style="text-align: center;">*发动机排量</td>
                <td><input type="text" name="engine_capacity" id="engine_capacity" class="layui-input" lay-verify="required" value="{$info['engine_capacity']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">运输证字号</td>
                <td><input type="text" name="transport_number" id="transport_number" class="layui-input" value="{$info['transport_number']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*车辆运输证发证机构</td>
                <td><input type="text" name="issuing_agency" id="issuing_agency" class="layui-input" lay-verify="required" value="{$info['issuing_agency']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*车辆经营区域</td>
                <td><input type="text" name="manage_area" id="manage_area" class="layui-input" lay-verify="required" value="{$info['manage_area']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*运输证有效期起</td>
                <td><input type="text" name="valid_start" id="valid_start" class="layui-input" lay-verify="required" value="{$info['valid_start']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*运输证有效期止</td>
                <td><input type="text" name="valid_end" id="valid_end" class="layui-input" lay-verify="required" value="{$info['valid_end']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*车辆初次登记日期</td>
                <td><input type="text" name="first_register_date" id="first_register_date" class="layui-input" lay-verify="required" value="{$info['first_register_date']}"></td>
            </tr>
            <tr>
            <td style="text-align: center;">*车辆检修状态</td>
            <td>
                <select name="inspection_status" id="inspection_status" lay-filter="inspection_status" lay-verify="required">
                    <if condition="$inspection_status_select">
                        <volist name="inspection_status_select" id="vo">
                            <option value="{$key}">{$vo}</option>
                        </volist>
                        <else />
                        <option value="">请选择检修状态</option>
                    </if>
                    <volist name="inspection_status" id="vo">
                        <option value="{$key}">{$vo}</option>
                    </volist>
                </select>
            </td>
            </tr>
            <tr>
                <td style="text-align: center;">车辆下次年检时间</td>
                <td><input type="text" name="next_annual_inspection_time" id="next_annual_inspection_time" class="layui-input" value="{$info['next_annual_inspection_time']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*车辆年度审验状态</td>
                <td>
                    <select name="annual_review_status" id="annual_review_status" lay-filter="annual_review_status" lay-verify="required">
                        <if condition="$annual_review_status_select">
                            <volist name="annual_review_status_select" id="vo">
                                <option value="{$key}">{$vo}</option>
                            </volist>
                            <else />
                            <option value="">请选择年度审验状态</option>
                        </if>
                        <volist name="annual_review_status" id="vo">
                            <option value="{$key}">{$vo}</option>
                        </volist>
                    </select>
                </td>
            </tr>

            <tr>
                <td style="text-align: center;">*发票打印序列号</td>
                <td><input type="text" name="fee_print_id" id="fee_print_id" class="layui-input" lay-verify="required" value="{$info['fee_print_id']}"></td>
            </tr>

            <tr>
                <td style="text-align: center;">*GPS品牌</td>
                <td><input type="text" name="gps_brand" id="gps_brand" class="layui-input" lay-verify="required" value="{$info['gps_brand']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*GPS型号</td>
                <td><input type="text" name="gps_model" id="gps_model" class="layui-input" lay-verify="required" value="{$info['gps_model']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">IMEI号</td>
                <td><input type="text" name="imei_number" id="imei_number" class="layui-input" value="{$info['imei_number']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*安装日期</td>
                <td><input type="text" name="install_date" id="install_date" class="layui-input" lay-verify="required" value="{$info['install_date']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*报备日期</td>
                <td><input type="text" name="register_date" id="register_date" class="layui-input" lay-verify="required" value="{$info['register_date']}"></td>
            </tr>
            <tr>
                <td style="text-align: center;">*服务类型</td>
                <td>
                    <div class="layui-input-block" id="service_type">
                        <input type="radio" lay-filter="type" name="service_type" value="1" title="私人小客车合乘" checked>
                        <input type="radio" lay-filter="type" name="service_type" value="2" title="巡游出租汽车" <if condition="$info['service_type'] eq 2"> checked</if>>
                        <input type="radio" lay-filter="type" name="service_type" value="3" title="网络预约出租汽车" <if condition="$info['service_type'] eq 3"> checked</if>>
                    </div>
                </td>
            </tr>

            <tr>
                <td colspan="2">
                    <button class="layui-btn" lay-submit="" lay-filter="submit" id="submits">提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </td>
            </tr>
        </table>
    </form>
    <script>
        layui.use(['form','laydate','upload'], function () {
            form = layui.form
                ,laydate = layui.laydate
                ,upload = layui.upload;

            form.on('select(province)', function(data){
                var province_id = data.value;
                if(province_id == 0){
                    $("#city_id").empty();
//                    $("#city_id").append('<option value=0>默认城市</option>');
                    form.render('select');
                    return false;
                }
                $("#city_id").empty();
                $("#city_id").append('<option value=>请选择城市</option>');
                $.ajax({
                    url:'{:url("/admin/Franchisee/cityList")}',
                    async:true,
                    //dataType:'json',
                    type:'post',
                    data:{'province_id':province_id},
                    success:function(res){
                        $("#city_id").append(res);
                        form.render('select');
                    },
                    error:function(e){
                        layer.msg('请求错误');return false;
                    }
                })
            });

            //常规用法
            laydate.render({
                elem: '#valid_start'
            });
            laydate.render({
                elem: '#valid_end'
            });
            laydate.render({
                elem: '#first_register_date'
            });
            laydate.render({
                elem: '#next_annual_inspection_time'
            });
            laydate.render({
                elem: '#install_date'
            });
            laydate.render({
                elem: '#register_date'
            });

            $("#submits").click(function () {
                var formStr=$("#formId").serialize();
                //序列化中文时之所以乱码是因为.serialize()调用了encodeURLComponent方法将数据编码了
                //原因：.serialize()自动调用了encodeURIComponent方法将数据编码了
                //解决方法：调用decodeURIComponent(XXX,true);将数据解码
                var params = decodeURIComponent(formStr,true); //关键点

                $.post('/admin/Carcj/supplement_submits',{
                    data:params
                },function (res) {
                    switch (res.status){
                        case 1:
                            alert(res.msg);
                            // 向java 提交 交通部接口数据
                            ajax_post_java(params);
                            break;
                        default:
                            layer.msg(res['msg'],{icon: 5});
                            break;
                    }
                },'json');
                return false;
            });
        });

        function ajax_post_java(params) {
            $.ajax({
                url:"/admin/Carcj/ajax_supplement",
                type:"POST",
                data:params,
                contentType:"text/html;charset=utf8",
                dataType:"json",
                success:function (res) {
                    if(res.code === 200) {
                        console.log(res.msg);
                    } else {
                        console.log(res.msg);
                    }
                }
            });
        }

    </script>
</block>